<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // https://leetcode-cn.com/problems/reshape-the-matrix/
        // 这题还是挺有意思的，先把mat多维数组转成一维，然后再切割就完事了
        var matrixReshape = function(mat, r, c) {
            let arr = [];
            for (let i = 0; i < mat.length; i++) {
                arr = [...arr, ...mat[i]]
            }
            if (arr.length !== r * c) {
                return mat;
            } else {
                mat = [];
                for (let i = 0; i < r; i++) {
                    let tmp = [];
                    tmp = arr.slice(c * i, c + c * i);
                    mat.push(tmp)
                }
                return mat;
            }
        };
        console.log(matrixReshape([[1,2],[3,4],[5,6]], 2, 3));
    </script>
</body>
</html>